package com.tianbing.adlottery.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.fengniu.ejb.business.ITagLogBusiness;
import com.fengniu.ejb.dao.ICategoryDao;
import com.fengniu.ejb.dao.IContentDao;
import com.fengniu.ejb.dao.ISiteDao;
import com.fengniu.ejb.dao.ISystemDao;
import com.fengniu.ejb.dao.IUserDao;
import com.fengniu.ejb.entity.Content2Content;
import com.fengniu.ejb.entity.Site;
import com.tianbing.adlottery.global.IConstants;
import com.tianbing.adlottery.helper.SkinUtils;

/**
 * MultiActionController for the image list/upload UI.
 * 
 * @author Conan Chen
 * @since 2006.12.15
 */
public class HomeController extends MultiActionController {
	Logger logger = Logger.getLogger(HomeController.class.getName());

	private String homeView;

	private String storeView;


	private String companyView;

	private ISiteDao siteDao;

	private IUserDao userDao;

	private IContentDao contentDao;

	private ICategoryDao categoryDao;

	private ITagLogBusiness tagLogBusiness;

	private SkinUtils skinUtils;

	private ISystemDao systemDao;

	public ModelAndView showHome(HttpServletRequest request, HttpServletResponse response) throws Exception {

		ModelAndView mv = new ModelAndView(homeView);
		Map<String, Object> model = mv.getModel();
		return mv;
	}

	/**
	 * used for dispatch to site(store or company) by sub-domain e.g.
	 * hgz.productsnearby.com will redirect to /viewstoredetail.jsp?siteid=hgz
	 * or /viewcompanydetail.jsp?siteid=hgz
	 * 
	 * note: hgz.productsnearby.com will first translated to
	 * /viewsitedetail.jsp?siteid=hgz by apache or jboss server url rewriter
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ModelAndView showStoreOrCompany(HttpServletRequest request, HttpServletResponse response) throws Exception {

		ModelAndView mv = new ModelAndView(storeView);

		String siteid = ServletRequestUtils.getStringParameter(request, "siteid", null);
		if (siteid == null) {
			this.showHome(request, response);
		} else {
			Site s = siteDao.findSiteBySiteId(siteid);
			if (s.getTypeId().compareTo(IConstants.Type.SITE_COMPANY.getId()) == 0)
				mv = new ModelAndView(companyView + "?siteid=" + siteid);
			else
				mv = new ModelAndView(storeView + "?siteid=" + siteid);
		}
		return mv;
	}

	public void setCategoryDao(ICategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	public void setHomeView(String homeView) {
		this.homeView = homeView;
	}

	public void setSiteDao(ISiteDao siteDao) {
		this.siteDao = siteDao;
	}

	public void setSkinUtils(SkinUtils skinUtils) {
		this.skinUtils = skinUtils;
	}

	public void setSystemDao(ISystemDao systemDao) {
		this.systemDao = systemDao;
	}

	public void setContentDao(IContentDao contentDao) {
		this.contentDao = contentDao;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	public void setCompanyView(String companyView) {
		this.companyView = companyView;
	}

	public void setLogger(Logger logger) {
		this.logger = logger;
	}

	public void setStoreView(String storeView) {
		this.storeView = storeView;
	}

	

	public void setTagLogBusiness(ITagLogBusiness tagLogBusiness) {
		this.tagLogBusiness = tagLogBusiness;
	}

}
